/**
 * 企业js
 */

$(function() {
	initialPage();
	getGrid();
});

function initialPage() {
	$(window).resize(function() {
		$('#dataGrid').bootstrapTable('resetView', {
			height : $(window).height() - 56
		});
	});
}

function getGrid() {
	$('#dataGrid').bootstrapTableEx({
		url : '../../sys/userenterprise/list?_' + $.now(),
		height : $(window).height() - 56,
		queryParams : function(params) {
			params.name = vm.keyword;
			return params;
		},
		columns : [ {
			checkbox : true
		}, {
			field : "createTime",
			title : "创建时间",
			width : "120px"
		},{
			field : "name",
			title : "企业名称",
			width : "100px"
		}, {
			field : "shortName",
			title : "企业简称",
			width : "100px"
		},{
			field : "businessLicense",
			title : "营业执照",
			width : "100px",
			formatter: function (value, row, index) {
				 vm.imgId = value.split(".")[0];
             return '<img class ="myImg" id="img_'+vm.imgId+'" src="http://qiniudns.zaishengwang.com/'+value+'"  alt="" onmousemove="vm.scaleImg('+vm.imgId+')" onmouseout="vm.smallImg()">';
         }
		}, {
			field : "socialCreditCode",
			title : "统一社会信用代码",
			width : "100px"
		}, {
			field : "enterpriseAuthorization",
			title : "企业授权书",
			width : "100px",
			formatter: function (value, row, index) {
				 vm.imgId = value.split(".")[0];
            return '<img class ="myImg" id="img_'+vm.imgId+'" src="http://qiniudns.zaishengwang.com/'+value+'"  alt="" onmousemove="vm.scaleImg('+vm.imgId+')" onmouseout="vm.smallImg()">';
        }
		},{
			field : "corporateRepresentative",
			title : "法人代表",
			width : "100px"
		}, {
			field : "corporateCard",
			title : "法人身份证",
			width : "100px"
		}, {
			field : "corporateCardFacade",
			title : "法人身份证正面",
			width : "100px",
			formatter: function (value, row, index) {
				vm.imgId = value.split(".")[0];
               return '<img class ="myImg" id="img_'+vm.imgId+'" src="http://qiniudns.zaishengwang.com/'+value+'"  alt="" onmousemove="vm.scaleImg('+vm.imgId+')" onmouseout="vm.smallImg()">';
           }
		}, {
			field : "corporateCardOpposite",
			title : "法人身份证反面",
			width : "100px",
			formatter: function (value, row, index) {
				 vm.imgId = value.split(".")[0];
              return '<img class ="myImg" id="img_'+vm.imgId+'" src="http://qiniudns.zaishengwang.com/'+value+'"  alt="" onmousemove="vm.scaleImg('+vm.imgId+')" onmouseout="vm.smallImg()">';
          }
		} ]
	})
}

var vm = new Vue({
	el : '#dpLTE',
	data : {
		imgId:"",
		keyword : null
	},
	methods : {
		load : function() {
			$('#dataGrid').bootstrapTable('refresh');
		},
		save : function() {
			dialogOpen({
				title : '新增企业',
				url : 'base/userenterprise/add.html?_' + $.now(),
				width : '420px',
				height : '350px',
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		edit : function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections');
			if (checkedRow(ck)) {
				dialogOpen({
					title : '编辑企业',
					url : 'base/userenterprise/edit.html?_' + $.now(),
					width : '630px',
					height : '620px',
					success : function(iframeId) {
						top.frames[iframeId].vm.userEnterprise.id = ck[0].id;
						top.frames[iframeId].vm.setForm();
					},
					yes : function(iframeId) {
						top.frames[iframeId].vm.acceptClick();
					}
				});
			}
		},
		remove : function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];
			if (checkedArray(ck)) {
				$.each(ck, function(idx, item) {
					ids[idx] = item.id;
				});
				$.RemoveForm({
					url : '../../sys/userenterprise/remove?_' + $.now(),
					param : ids,
					success : function(data) {
						vm.load();
					}
				});
			}
		},
		scaleImg: function (value){
			console.log(value);
			$(".shadow").css({
				"display":"block"
			});
			src_ = $("#img_"+value).attr("src");
			$(".myBigImg").attr({"src": src_});
		},
		smallImg: function () {
			$(".shadow").css({
				"display":"none"
			});

		}
	}
})